package com.snack.shop.task;

import com.snack.shop.service.RefundService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 退款自动审核定时任务
 * 
 * @author 阿狄
 * @date 2025-11-13
 */
@Component
@RequiredArgsConstructor
@Slf4j
public class RefundAutoApprovalTask {

    private final RefundService refundService;

    /**
     * 自动审核超时退款
     * 每10分钟执行一次
     */
    @Scheduled(cron = "0 */10 * * * ?")
    public void autoApproveOverdueRefunds() {
        try {
            log.debug("开始执行退款自动审核任务");
            refundService.autoApproveOverdueRefunds();
            log.debug("退款自动审核任务执行完成");
        } catch (Exception e) {
            log.error("退款自动审核任务执行失败", e);
        }
    }
}
